
use "$clean/clean_all.dta", clear

  
tempfile main
save `main', replace

clear all
eststo clear
estimates drop _all

loc columns = 4

set obs 10
gen x = 1
gen y = 1

forval i = 1/`columns' {
	eststo col`i': reg x y
} 

loc count = 1

loc statnames ""
loc varlabels ""

use  "$clean/clean_all.dta", clear

/* Custom fill cells */

gen beh=. //Generate placeholder for behavioral dat
gen inte=.
gen pred=.

label var pred "\underline{Covariates:}" 
label var female "Female"
label var age "Age (\#)"
label var member "Party member"
label var years_member "Years of membership (\#)"
label var experience "Experienced canvasser"
label var canv_workshop "Participated in workshop"
label var app_before_main "Downloaded app"

label var inte "\underline{Survey outcomes}"
label var beh "\underline{Behavioral outcomes}"
*label var app_before_main  "Downloaded app before survey"
la var prior_comp "Prior belief about competitor"
label var canvass_any_before_main_unres "Has canvassed before survey"
label var days_unres_before_main  "Days canvassed before survey"
label var doors_unres_before_main  "Doors visited before survey"
label var canvass_any_main_unres "Any canvassing"
label var days_unres_main "Cavassed days (\#)"
label var doors_unres_main_wins "Canvassed doors (\#)"

label var posterior_comp "Posterior belief about competitor"
label var canvassing_yes  "Planned canvassing"
label var  days "Planned days (\#)"


foreach yvar of varlist  pred female age member years_member experience canv_workshop app_before_main ///
prior_comp  inte posterior_comp  canvassing_yes days beh canvass_any_main_unres days_unres_main doors_unres_main_wins{

	qui sum `yvar', d
	if `r(N)'!=0 {
	cap: estadd loc thisstat`count' = string(`r(mean)', "%9.2f"): col1
	cap: estadd loc thisstat`count' = string(`r(min)', "%9.2f"): col2
	cap: estadd loc thisstat`count' = string(`r(max)', "%9.2f"): col3
	cap: estadd loc thisstat`count' = `r(N)': col4
	}
	/* Row Labels */
	
	loc thisvarlabel: variable label `yvar'
	local varlabels "`varlabels' "`thisvarlabel'" "
	loc statnames "`statnames' thisstat`count'"
	loc count = `count' + 1
	
}

/* Footnotes */

loc prehead "\begin{tabular}{l*{`columns'}{c}} \toprule"

loc postfoot "\bottomrule \end{tabular}"

esttab col* using "$tables/Table_A1", booktabs cells(none) nonum nogap mtitle("Mean" "Min." "Max." "Obs.") stats(`statnames', labels(`varlabels')) note("`footnote'") prehead("`prehead'") postfoot("`postfoot'") compress wrap replace

eststo clear

